<template>
  <div>
    <h1>小熊大</h1>
    <button @click="btn">小熊大找周坚伟</button>
    <button @click="testEventBus">test utils eventBus</button>
  </div>
</template>

<script>
/* 
$emit $on eventBus(在任意组件中传值)

先在当前组件进行传值


$emit 分发触发事件
$on 绑定事件


*/
import EventBus from "../utils/eventBus";
export default {
  name: "",
  props: [""],
  data() {
    return {
      msg: "乖，给你一块糖！！",
    };
  },

  components: {},

  computed: {},

  beforeMount() {},

  mounted() {
    //   绑定事件
    this.$on("jianwei", (msg) => {
      console.log(msg);
      console.log("我是周坚伟");
    });
    // 触发事件
    this.$emit("jianwei", this.msg);
  },

  methods: {
    btn() {
      this.$emit("jianwei", this.msg);
    },
    testEventBus() {
      EventBus.$emit("givexiaoxiongda", "给熊二一个蜂蜜罐");
    },
  },

  watch: {},
};
</script>
<style lang='' scoped>
</style>